<template>
    <div>
        <page-header :title="'个人博客总访问量: '+ accessSize">
            <template #content>
                <div>
                    <div>注：同一IP多次访问，也只计成一次访问</div>
                </div>
            </template>
        </page-header>
        <el-row :gutter="20" style="margin: 0 10px;">
            <!-- <el-col :lg="8">
                <page-main title="访问者地区" style="margin: 0 0 20px 0;">
                    <div id="container" ref="container" style="width: 100%; height: 500px;" />
                </page-main>
            </el-col> -->
            <el-col>
                <el-row :gutter="20" style="margin: 0 -10px 20px -10px;">
                    <el-col :md="6">
                        <div class="icon-box icon-box-1">
                            <div class="title">博客数</div>
                            <span>{{ blogSize }}</span>
                        </div>
                    </el-col>
                    <el-col :md="6">
                        <div class="icon-box icon-box-2">
                            <div class="title">留言数</div>
                            <span>{{ commentSize }}</span>
                        </div>
                    </el-col>
                    <el-col :md="6">
                        <div class="icon-box icon-box-3">
                            <div class="title">文章类别</div>
                            <span>暂无</span>
                        </div>
                    </el-col>
                </el-row>
                <page-main title="访问者信息" style="margin: 0 0 20px 0;">
                    <el-table
                        border
                        :data="accesssArr"
                        style="width: 100%;"
                    >
                        <el-table-column
                            prop="date"
                            label="日期"
                        />
                        <el-table-column
                            prop="ip"
                            label="IP"
                        />
                        <el-table-column
                            prop="address"
                            label="地址"
                        />
                        <el-table-column
                            prop="Operator"
                            label="运营商"
                        />
                    </el-table>
                </page-main>
            </el-col>
        </el-row>
    </div>
</template>

<script>

import { getAccess, getBlogAndMessgeSize } from '@/api/myIndex'
export default {
    data() {
        return {
            accessSize: 0,
            accesssArr: null,
            blogSize: 0,
            commentSize: 0
        }
    },
    mounted() {
        this.getInfo()
        this.getSize()
    },
    methods: {
        async getInfo() {
            let {code, message, data} = await getAccess()
            if (code === 200 && message === '成功') {
                this.accesssArr = data
                this.accessSize = data.length
                return
            }
            this.$message.error(message)
        },

        async getSize() {
            let {code, message, data} = await getBlogAndMessgeSize()
            if (code === 200 && message === '成功') {
                this.blogSize = data.blog
                this.commentSize = data.comment
                return
            }
            this.$message.error(message)
        }
    }
}
</script>

<style lang="scss" scoped>
.fa-info {
    padding: 10px 0 0;
    text-align: center;
    h1 {
        margin: 10px auto 20px;
    }
}
.question {
    .answer {
        margin: 20px 0 0;
        padding-left: 20px;
        font-size: 14px;
        color: #aaa;
        li {
            margin-bottom: 10px;
            line-height: 1.5;
            &:last-child {
                margin-bottom: 0;
            }
        }
        span {
            color: #666;
            font-weight: bold;
        }
    }
}
.icon-box {
    padding: 20px;
    text-align: center;
    background-color: #fff;
    cursor: pointer;
    transition: 0.2s;
    &:hover {
        color: #fff;
    }
    &-1 {
        color: #ffc069;
        &:hover {
            background-color: #ffc069;
        }
    }
    &-2 {
        color: #b37feb;
        &:hover {
            background-color: #b37feb;
        }
    }
    &-3 {
        color: #95de64;
        &:hover {
            background-color: #95de64;
        }
    }
    &-4 {
        color: #ff85c0;
        &:hover {
            background-color: #ff85c0;
        }
    }
    &-5 {
        color: #ff9c6e;
        &:hover {
            background-color: #ff9c6e;
        }
    }
    &-6 {
        color: #282c34;
        &:hover {
            background-color: #282c34;
        }
    }
    i {
        font-size: 24px;
    }
    .title {
        margin-top: 5px;
        font-size: 14px;
    }
}
</style>
